package fun.ticsmyc.designPattern;

/**
 * 写在类里面的单例
 * @author Ticsmyc
 * @package fun.ticsmyc.designPattern
 * @date 2020-08-13 20:15
 */
public class Singleton5 {

    enum Holder{

        INSTANCE;

        private Singleton5 singleton5;
        private Holder(){
            System.out.println("创建");
            singleton5 = new Singleton5();
        }
        public Singleton5 getInstance(){
            return singleton5;
        }

    }

    private Singleton5(){}

    public static Singleton5 getInstance(){
        return Holder.INSTANCE.getInstance();
    }

    public static void main(String[] args) {
        System.out.println("hi");
        System.out.println(Holder.INSTANCE.getInstance());
    }
}
